﻿using System;
using System.Collections.Generic;
using System.Drawing.Design;
using System.Runtime.Remoting.Contexts;
using System.Text;
using System.Windows.Forms;
using System.Windows.Forms.Design;

namespace LegtionMVVM
{
    public class BindingEditor: UITypeEditor
    {
        public override UITypeEditorEditStyle GetEditStyle(System.ComponentModel.ITypeDescriptorContext context)
        {
            return UITypeEditorEditStyle.Modal;
        }

        public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, IServiceProvider provider, object value)
        {            
            IWindowsFormsEditorService editorService = null;
            if (provider != null)
            {
                editorService = provider.GetService(typeof(IWindowsFormsEditorService)) as IWindowsFormsEditorService;
            }

            if (editorService != null)
            {

                FormBindingEditor editor = new FormBindingEditor(context.Instance as Control);
                editor.Bindings = (string)value;               

                if (editorService.ShowDialog(editor) == System.Windows.Forms.DialogResult.OK)
                {
                    value = editor.Bindings;
                }

            }
            return value;
        }
    }
    public class CommandEditor : UITypeEditor
    {
        public override UITypeEditorEditStyle GetEditStyle(System.ComponentModel.ITypeDescriptorContext context)
        {
            return UITypeEditorEditStyle.Modal;
        }

        public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            IWindowsFormsEditorService editorService = null;
            if (provider != null)
            {
                editorService = provider.GetService(typeof(IWindowsFormsEditorService)) as IWindowsFormsEditorService;
            }

            if (editorService != null)
            {
                FormCommanEditor editor = new FormCommanEditor(context.Instance as Control);
                editor.Scripts = (string)value;

                if (editorService.ShowDialog(editor) == System.Windows.Forms.DialogResult.OK)
                {
                    value = editor.Scripts;
                }
            }

            return value;
        }
    } 
}
